package com.qf.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author 29125
 * @version V1.0
 * @Project java2203
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}过滤器
 * @Date 2022/5/22 22:19
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
        //处理请求对象字符集编码
        servletRequest.setCharacterEncoding("utf-8");
        //处理响应对象字符集编码
        servletResponse.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text/html;charset=utf-8");

        //放行请求，到下一个过滤器
        filterChain.doFilter(servletRequest, servletResponse);
    }

    public void destroy() {
    }

}
